clear;clc;
overline_s= @(tau,eta,u,mu) ((tau+eta)./eta).*u - (tau.*mu)./eta;

%MALE PARAMETERS
u=6; 
mu=5; %cherry picking
tau=.5; %dispersion
eta=2; %signal precision
sM=overline_s(tau,eta,u,mu);

%drawbrace([mu,u], [mu,u_F], 10, 'Color', 'k')
%drawbrace([muF,u], [mu,u], 10, 'Color', 'k')
%pos = get(gca, 'Position')

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%Prop 1: Isodiscrimination curves 
u_F=[5.7:.3:6.9];
sF=overline_s(tau,eta,u_F,mu); %sF for type w/ preference partiality & belief neutrality
muF=[0:.01:mu+1];
for i=1:length(sF);for j=1:length(muF);
%row: signal cut-off sF; column: equivalent uF for each muF
uF_equiv(i,j) = muF(j).*(tau./(tau+eta)) + sF(i) .*eta./(tau+eta); 
end;end;

PrefNeutrality=ones(1,length(muF))*u; %line u_F=u_M
BeliefNeutrality=ones(1,length(uF_equiv))*mu; %line \hat mu_F=\hat mu

figure(2)
hold on;
xlim([0 6]);ylim([5.8 7]);
plot(muF,PrefNeutrality,'b--','LineWidth',1) %preference neutrality
plot(BeliefNeutrality,uF_equiv,'g-.','LineWidth',1) %belief neutrality
plot(muF,uF_equiv(5,:),'k','LineWidth',2) %isodiscrimination curve
plot(muF,uF_equiv(4,:),'k','LineWidth',2) %isodiscrimination curve
plot(muF,uF_equiv(3,:),'k','LineWidth',2) %isodiscrimination curve
plot(muF,uF_equiv(2,:),'r','LineWidth',2) %isodiscrimination curve: no discrimination
plot(muF,uF_equiv(1,:),'k','LineWidth',2) %isodiscrimination curve: against men
set(gca,'FontSize',14,'FontName', 'TimesNewRoman')
xlabel('Perceived Average Productivity $$\hat{\mu}_F$$','Interpreter','Latex')
ylabel('Preference Parameter $$u_F$$','Interpreter','Latex')
str1={'Isodiscrimination curves'};
str2={'No discrimination'};
str3={'Belief neutrality $$\hat{\mu}_F=\hat{\mu}_M$$'};
str4={'Preference neutrality $$u_F=u_M$$'};
a2=annotation('textbox','String',str1,'EdgeColor','none','Interpreter','Latex')
a3=annotation('textbox','String',str2,'EdgeColor','none','Interpreter','Latex')
a4=annotation('textbox','String',str3,'EdgeColor','none','Interpreter','Latex')
a5=annotation('textbox','String',str4,'EdgeColor','none','Interpreter','Latex')
a3.FontSize=16;a4.FontSize=16;a5.FontSize=16;a2.FontSize=16;
hold off;

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%Prop 2: isodiscrimination - preference vs. mean
u_F=6.4;
sF=overline_s(tau,eta,u_F,mu); %sF for type w/ preference partiality & belief neutrality
u_prime=[5.5:.05:7.5]; 
mu_prime = ((tau+eta)./tau).*u_prime-eta./tau.*sF;
muF_equiv = ((tau+eta)./tau).*u-eta./tau.*sF; % \hat \mu_F for type w/ preference neutrality & belief partiality
mu_noD = ((tau+eta)./tau).*u_prime-eta./tau.*sM;

PrefNeutrality=ones(1,length(u_prime))*u; %line u_F=u
BeliefNeutrality=ones(1,length(u_prime))*mu; %line \hat mu_F=\hat mu

figure(3)
hold on;
xlim([2.5 5.5]);ylim([5.9 6.5]);
plot(mu_prime,PrefNeutrality,'b--','LineWidth',2) %preference neutrality
plot(BeliefNeutrality,u_prime,'g-.','LineWidth',2) %belief neutrality
plot(mu_prime,u_prime,'k','LineWidth',2) %isodiscrimination
plot(mu_noD,u_prime,'k:','LineWidth',1) %no discrimination
%plot(mu,u,'ro','MarkerSize',7) %preference + belief neutrality
plot(mu,u_F,'r*','MarkerSize',5) %no belief-based
plot(muF_equiv,u,'r*','MarkerSize',5) %no preference-based
set(gca,'FontSize',14,'FontName', 'TimesNewRoman')
xlabel('Perceived Average Productivity $$\hat{\mu}_F$$','Interpreter','Latex')
ylabel('Preference Parameter $$u_F$$','Interpreter','Latex')
str1={'Types that exhibit equivalent discrimination'};
str2={'No discrimination'};
str3={'Belief neutrality $$\hat{\mu}_F=\hat{\mu}_M$$'};
str4={'Preference neutrality $$u_F=u_M$$'};
a1=annotation('textbox','String',str1,'EdgeColor','none','Interpreter','Latex')
a3=annotation('textbox','String',str2,'EdgeColor','none','Interpreter','Latex')
a4=annotation('textbox','String',str3,'EdgeColor','none','Interpreter','Latex')
a5=annotation('textbox','String',str4,'EdgeColor','none','Interpreter','Latex')
a1.FontSize=16;a3.FontSize=16;a4.FontSize=16;a5.FontSize=16;
hold off;

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%Prop 2: isodiscrimination - preference vs. concentration
u_F=6.4;
sF=overline_s(tau,eta,u_F,mu); %sF for type w/ preference partiality & belief neutrality
u_prime=[5.5:.05:7.5]; 
tau_prime = eta.*(sF-u_prime)./(u_prime-mu);
tauF_equiv = eta.*(sF-u)./(u-mu);
tau_noD = eta.*(sM-u_prime)./(u_prime-mu);
%tauF_equiv = tau.*(u_F-mu)./(u-mu) + eta.*(u_F-u)./(u-mu);

PrefNeutrality=ones(1,length(u_prime))*u; %line u_F=u
BeliefNeutrality=ones(1,length(u_prime))*tau; %line \hat tau_F=\hat tau

figure(4)
hold on;
xlim([.25 2]);ylim([5.9 6.6]);
plot(tau_prime,PrefNeutrality,'b--','LineWidth',2) %preference neutrality
plot(BeliefNeutrality,u_prime,'g-.','LineWidth',2) %belief neutrality
plot(tau_prime,u_prime,'k','LineWidth',2) %isodiscrimination
plot(tau_noD,u_prime,'k:','LineWidth',1) %no discrimination
%plot(tau,u,'ro','MarkerSize',7) %preference + belief neutrality
plot(tau,u_F,'r*','MarkerSize',5) %no belief-based
plot(tauF_equiv,u,'r*','MarkerSize',5) %no preference-based
xlabel('Perceived Concentration of Productivity $$\hat{\tau}_F$$','Interpreter','Latex')
ylabel('Preference Parameter $$u_F$$','Interpreter','Latex')
str1={'Types that exhibit equivalent discrimination'};
str2={'No discrimination'};
str3={'Belief neutrality $$\hat{\tau}_F=\hat{\tau}_M$$'};
str4={'Preference neutrality $$u_F=u_M$$'};
set(gca,'FontSize',14,'FontName', 'TimesNewRoman')
a1=annotation('textbox','String',str1,'EdgeColor','none','Interpreter','Latex')
a3=annotation('textbox','String',str2,'EdgeColor','none','Interpreter','Latex')
a4=annotation('textbox','String',str3,'EdgeColor','none','Interpreter','Latex')
a5=annotation('textbox','String',str4,'EdgeColor','none','Interpreter','Latex')
a1.FontSize=16;a3.FontSize=16;a4.FontSize=16;a5.FontSize=16;
hold off;


%Prop 2: isodiscrimination - preference vs. signal precision
u_F=6.4;
sF=overline_s(tau,eta,u_F,mu); %sF for type w/ preference partiality & belief neutrality
u_prime=[5.5:.01:7.5]; 
eta_prime = tau.*(u_prime-mu)./(sF-u_prime);
etaF_equiv = tau.*(u-mu)./(sF-u);
eta_noD= tau.*(u_prime-mu)./(sM-u_prime);

PrefNeutrality=ones(1,length(u_prime))*u; %line u_F=u
BeliefNeutrality=ones(1,length(u_prime))*eta; %line \hat tau_F=\hat tau

figure(5)
hold on;
xlim([.4 2.2]);ylim([5.9 6.5]);
plot(eta_prime,PrefNeutrality,'b--','LineWidth',2) %preference neutrality
plot(BeliefNeutrality,u_prime,'g-.','LineWidth',2) %belief neutrality
plot(eta_prime,u_prime,'k','LineWidth',2) %isodiscrimination
plot(eta_noD,u_prime,'k:','LineWidth',1) %no discrimination
%plot(eta,u,'ro','MarkerSize',7) % preference + belief neutrality
plot(eta,u_F,'r*','MarkerSize',5) %no belief-based
plot(etaF_equiv,u,'r*','MarkerSize',5) %no preference-based
xlabel('Perceived Signal Precision $$\hat{\eta}_F$$','Interpreter','Latex')
ylabel('Preference Parameter $$u_F$$','Interpreter','Latex')
str1={'Types that exhibit equivalent discrimination'};
str2={'No discrimination'};
str3={'Belief neutrality $$\hat{\eta}_F=\hat{\eta}_M$$'};
str4={'Preference neutrality $$u_F=u_M$$'};
set(gca,'FontSize',14,'FontName', 'TimesNewRoman')
a1=annotation('textbox','String',str1,'EdgeColor','none','Interpreter','Latex')
a2=annotation('textbox','String',str2,'EdgeColor','none','Interpreter','Latex')
a3=annotation('textbox','String',str3,'EdgeColor','none','Interpreter','Latex')
a4=annotation('textbox','String',str4,'EdgeColor','none','Interpreter','Latex')
a1.FontSize=16;a3.FontSize=16;a4.FontSize=16;a2.FontSize=16;
hold off;


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%Obs 2: accurate beliefs
u_F=6.4;
muF_accurate=4.5; % accurate belief
sF=overline_s(tau,eta,u_F,mu); %sF for type w/ preference partiality & belief neutrality
u_prime=[5.5:.05:7.5]; 
mu_prime = ((tau+eta)./tau).*u_prime-eta./tau.*sF;
muF_equiv = ((tau+eta)./tau).*u-eta./tau.*sF; % \hat \mu_F for type w/ preference neutrality & belief partiality
mu_noD = ((tau+eta)./tau).*u_prime-eta./tau.*sM;
index_accurate=0;
for j=1:length(u_prime);
    if mu_prime(j)==muF_accurate;index_accurate=j;end;
end;
u_prime(index_accurate)

BeliefAccurate=ones(1,length(u_prime))*muF_accurate; %line accurate mu_F
PrefNeutrality=ones(1,length(u_prime))*u; %line u_F=u
BeliefNeutrality=ones(1,length(u_prime))*mu; %line \hat mu_F=\hat mu

figure(6)
hold on;
xlim([2.5 5.5]);ylim([5.9 6.5]);
plot(mu_prime,PrefNeutrality,'b--','LineWidth',1) %preference neutrality
plot(BeliefNeutrality,u_prime,'g-.','LineWidth',1) %belief neutrality
plot(BeliefAccurate,u_prime,'k:','LineWidth',2) %accurate belief
plot(mu_prime,u_prime,'k','LineWidth',2) %isodiscrimination
plot(mu_noD,u_prime,'k:','LineWidth',1) %no discrimination
plot(muF_accurate,u_prime(index_accurate),'r*','MarkerSize',5) %accurate type
plot(muF_accurate,u,'r*','MarkerSize',5) %accurate statistical
set(gca,'FontSize',14,'FontName', 'TimesNewRoman')
xlabel('Perceived Average Productivity $$\hat{\mu}_F$$','Interpreter','Latex')
ylabel('Preference Parameter $$u_F$$','Interpreter','Latex')
str1={'Isodiscrimination curve'};
str2={'Accurate belief partiality $$\hat{\mu}_F=\mu_F$$'};
str3={'Belief neutrality $$\hat{\mu}_F=\hat{\mu}_M$$'};
str4={'Preference neutrality $$u_F=u_M$$'};
str5={'Type identified'};
str6={'Accurate statistical discriminator'};
str7={'No discrimination'};
a1=annotation('textbox','String',str1,'EdgeColor','none','Interpreter','Latex')
a2=annotation('textbox','String',str2,'EdgeColor','none','Interpreter','Latex')
a3=annotation('textbox','String',str3,'EdgeColor','none','Interpreter','Latex')
a4=annotation('textbox','String',str4,'EdgeColor','none','Interpreter','Latex')
a5=annotation('textbox','String',str5,'EdgeColor','none','Interpreter','Latex')
a6=annotation('textbox','String',str6,'EdgeColor','none','Interpreter','Latex')
a7=annotation('textbox','String',str7,'EdgeColor','none','Interpreter','Latex')
a1.FontSize=16;a2.FontSize=16;a3.FontSize=16;a4.FontSize=16;a6.FontSize=16;a5.FontSize=16;a7.FontSize=16;
hold off;


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%Prop 3: comparative static on info 

x=[1;2]; % # signal draws
u=6;
u_F=6.2;
u_prime=[5.5:.01:7.5]; %index for plot

%TYPE 1 
mu=5; %cherry picking
mu_F=4;
tau=.5; %dispersion
eta=1*x; %signal precision
sM=overline_s(tau,eta,u,mu);
sF=overline_s(tau,eta,u_F,mu_F); 
mu_prime = ((tau+eta)./tau).*u_prime-eta./tau.*sF; %isodiscrimination curve

%TYPE 2
tau_2=.4 %dispersion
eta_2=1*x %signal precision
mu_2 = u - (tau./eta)./(tau_2./eta_2).*(u-mu);
sM_2=overline_s(tau,eta,u,mu);
mu_2_F = u_F - (tau./eta)./(tau_2./eta_2).*(u_F-mu_F)
sF_2=overline_s(tau_2,eta_2,u_F,mu_2_F); %sF for type w/ preference partiality & belief neutrality
mu_prime2 = ((tau_2+eta_2)./tau_2).*u_prime-eta_2./tau_2.*sF_2; %isodiscrimination curve

PrefNeutrality=ones(1,length(u_prime))*u; %line u_F=u
BeliefNeutrality=ones(1,length(u_prime))*mu; %line \hat mu_F=\hat mu
mu_index=[2.5:.05:4];
Pref_F=ones(1,length(mu_index))*u_F; %line u_F

figure(8)
hold on;
xlim([2.5 5.5]);ylim([5.9 6.5]);
%plot(mu_prime(1,:),PrefNeutrality,'b--','LineWidth',1) %preference neutrality
plot(mu_index,Pref_F,'b--','LineWidth',1) %line: u_F=6.2
%plot(BeliefNeutrality,u_prime,'g-.','LineWidth',1) %belief neutrality
plot(mu_prime(1,:),u_prime,'k','LineWidth',2) %isodiscrimination
plot(mu_prime(2,:),u_prime,'b','LineWidth',2) %isodiscrimination
%plot(mu_prime2(1,:),u_prime,'k','LineWidth',2) %isodiscrimination
%plot(mu_prime2(2,:),u_prime,'k','LineWidth',2) %isodiscrimination
plot(mu_F,u_F,'r*','MarkerSize',5) %actual type
set(gca,'FontSize',14,'FontName', 'TimesNewRoman')
xlabel('Perceived Average Productivity $$\hat{\mu}_F$$','Interpreter','Latex')
ylabel('Preference Parameter $$u_F$$','Interpreter','Latex')
str1={'Isodiscrimination curve: 1 draw'};
str2={'Isodiscrimination curve: 2 draws'};
str3={'Identified preference $$u_F=6.2$$'};
a1=annotation('textbox','String',str1,'EdgeColor','none','Interpreter','Latex')
a2=annotation('textbox','String',str2,'EdgeColor','none','Interpreter','Latex')
a3=annotation('textbox','String',str3,'EdgeColor','none','Interpreter','Latex')
a1.FontSize=16;a2.FontSize=16;a3.FontSize=16;
hold off;


%OLD: Type w/ preference partiality and belief neutrality
u=6; 
u_F=6.5;
mu=5; %cherry picking
tau=.5; %dispersion
eta=[1:2]; %signal precision
muF_accurate=2.5;

sF=overline_s(tau,eta,u_F,muF_accurate);
muF_equiv = muF_accurate - ((tau+eta)./tau).*(u_F-u); %type w/ preference neutrality
muF=[min(muF_equiv):.01:mu];
for i=1:length(sF);for j=1:length(muF);
%row: value of eta; column: equivalent uF for each muF
uF_equiv(i,j) = muF(j).*(tau./(tau+eta(i))) + sF(i) .*eta(i)./(tau+eta(i)); 
end;end;

hold on;
xlim([0 5]);ylim([6 7]);
plot(muF,uF_equiv(1,:),'k','LineWidth',2)
plot(muF,uF_equiv(1,:),'k','LineWidth',2)
plot(muF,uF_equiv(2,:),'b:','LineWidth',2)
plot(muF,uF_equiv(2,:),'b:','LineWidth',2)
plot(muF_accurate,u_F,'r*','MarkerSize',5)
set(gca,'FontSize',14,'FontName', 'TimesNewRoman')
xlabel('Perceived Average Productivity $$\hat{\mu}_F$$','Interpreter','Latex')
ylabel('Preference Parameter $$u_F$$','Interpreter','Latex')
str1={'Equivalent discrimination: 1 draw'};
str2={'Equivalent discrimination: 2 draws'};
str3={'Actual Belief + Preference'};
a1=annotation('textbox','String',str1,'EdgeColor','none')
a2=annotation('textbox','String',str2,'EdgeColor','none')
a3=annotation('textbox','String',str3,'EdgeColor','none')
a1.FontSize=16;a2.FontSize=16;a3.FontSize=16;
hold off;
